<template>
  <div style="min-height: 500px; margin: 20px auto; width: 80%; ">
    <div style="font-size: 18px">我预约的面试（{{ data.tableData.length }}）</div>
    <div class="card" style="margin-bottom: 5px; margin-top: 20px">
      <el-table stripe :data="data.tableData">
        <el-table-column prop="employName" label="企业名称" />
        <el-table-column prop="positionName" label="面试职位">
          <template v-slot="scope">
            <a :href="'/front/positionDetail?id=' + scope.row.positionId">{{ scope.row.positionName }}</a>
          </template>
        </el-table-column>
        <el-table-column prop="userName" label="面试用户" />
        <el-table-column prop="time" label="面试时间" />
        <el-table-column prop="status" label="面试状态">
          <template v-slot="scope">
            <el-tag v-if="scope.row.status === '不适合'" type="danger">{{ scope.row.status }}</el-tag>
            <el-tag v-if="scope.row.status === '面试中'" type="primary">{{ scope.row.status }}</el-tag>
            <el-tag v-if="scope.row.status === '通过'" type="success">{{ scope.row.status }}</el-tag>
            <el-tag v-if="scope.row.status === '不通过'" type="warning">{{ scope.row.status }}</el-tag>
            <el-tag v-if="scope.row.status === '已预约'" type="info">{{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120" fixed="right">
          <template v-slot="scope">
            <el-button type="danger" :disabled="scope.row.status !== '已预约'" @click="cancel(scope.row.id)">取消面试</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="card" v-if="data.total">
      <el-pagination @current-change="loadSubmit" background layout="prev, pager, next" :page-size="data.pageSize" v-model:current-page="data.pageNum" :total="data.total" />
    </div>
  </div>
</template>

<script setup>
import {reactive} from "vue";
import request from "@/utils/request.js";
import {ElMessage, ElMessageBox} from "element-plus";

const data = reactive({
  tableData: [],
  pageNum: 1,
  pageSize: 5,
  total: 0,
})

const loadSubmit = () => {
  request.get('/interview/selectPage', {
    params: {
      pageNum: data.pageNum,
      pageSize: data.pageSize
    }
  }).then(res => {
    if (res.code === '200') {
      data.tableData = res.data.list
      data.total = res.data.total
    }
  })
}

const cancel = (id) => {
  ElMessageBox.confirm('您确定放弃这次面试机会吗？', '放弃面试', { type: 'warning' }).then(res => {
    request.delete('/interview/delete/' + id).then(res => {
      if (res.code === '200') {
        ElMessage.success("取消成功")
        loadSubmit()
      } else {
        ElMessage.error(res.msg)
      }
    })
  }).catch(err => {
    console.error(err)
  })
}

loadSubmit()
</script>
